﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZyGame
{
    internal class TimeWheel : Singleton<TimeWheel>
    {
        private TimingWheelChild timingWheel;

        public TimeWheel()
        {
            timingWheel = new TimingWheelChild(3, 50);

        }

        private void UpdateTimingWheel()
        { 
        
        }

        public TimingWheelCancelledToken Subscribe(long time, ITimingWheelExecuted executed)
        {
            TimingWheelTaskData timingWheelTaskData = new TimingWheelTaskData(time, new TimingWheelCancelledToken(), executed);

            return timingWheelTaskData.cancelledToken;
        }

        public TimingWheelCancelledToken Subscribe(long time, Action action)
        {
            return Subscribe(time, new SimpleTimingWheelExecuted(action));
        }

        public TimingWheelCancelledToken Subscribe<T>(long time, Action<T> action, T args)
        {
            return Subscribe(time, new SimpleTimingWheelExecuted(() => { action(args); }));
        }


        class TimingWheelChild : IDisposable
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="index">轮编号</param>
            /// <param name="size">每个时间轮大小</param>
            public TimingWheelChild(int index, int size)
            {

            }
            public void Dispose()
            {
                throw new NotImplementedException();
            }
        }


        public sealed class TimingWheelCancelledToken : IDisposable
        {
            public void Dispose()
            {
                throw new NotImplementedException();
            }
        }

        public interface ITimingWheelExecuted : IDisposable
        {
            void Execut();
        }

        class SimpleTimingWheelExecuted : ITimingWheelExecuted
        {
            private Action callback;
            public SimpleTimingWheelExecuted(Action action)
            {
                this.callback = action;
            }


            public void Dispose()
            {
                callback = null;
            }

            public void Execut()
            {
                callback?.Invoke();
            }
        }

        class TimingWheelTaskData
        {
            public TimingWheelCancelledToken cancelledToken { get; }
            public TimingWheelTaskData(long time, TimingWheelCancelledToken token, ITimingWheelExecuted executed)
            {

            }
        }
    }
}
